package com.example.secondhandsysapi.Service;

import com.example.secondhandsysapi.Entity.LookLogInfo;
import com.example.secondhandsysapi.Mapper.LookLogInfoMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Locale;

@Service
public class LookLogInfoServiceImpl implements LookLogInfoService {
    @Autowired LookLogInfoMapper lookLogInfoMapper;


    @Override
    public Integer deleteByLookId(Integer look_id) {
        return lookLogInfoMapper.deleteByLookId(look_id);
    }

    @Override
    public List<LookLogInfo> getAllLookLogInfoAll() {
        return lookLogInfoMapper.getAllLookLogInfoAll();
    }

    @Override
    public List<LookLogInfo> getAllLookLogInfoByUserId(Integer user_id) {
        return lookLogInfoMapper.getAllLookLogInfoByUserId(user_id);
    }

    @Override
    public List<LookLogInfo> getAllLookLogInfoByPage(String log_page) {
        return lookLogInfoMapper.getAllLookLogInfoByPage(log_page);
    }

    @Override
    public List<LookLogInfo> getAllLookLogInfoByUserIdPage(Integer user_id, String log_page) {
        return lookLogInfoMapper.getAllLookLogInfoByUserIdPage(user_id,log_page);
    }

    @Override
    public List<LookLogInfo> getAllLookLogInfoByTime(Date log_time) {
        SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US);
        Date date = new Date();
        try {
            date = sdf.parse(String.valueOf(log_time));
        } catch (Exception e) {
            e.printStackTrace();
        }
        String formatStr = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date);
        return lookLogInfoMapper.getAllLookLogInfoByTime(formatStr);
    }

    @Override
    public List<LookLogInfo> getAllLookLogInfoByUserIdTime(Integer user_id, Date log_time) {
        return lookLogInfoMapper.getAllLookLogInfoByUserIdTime(user_id, log_time);
    }

    @Override
    public List<LookLogInfo> getAllLookLogInfoByTimePage(Date log_time, String log_page) {

        return lookLogInfoMapper.getAllLookLogInfoByTimePage(log_time, log_page);
    }


    @Override
    public List<LookLogInfo> getAllLookLogInfoByUserIdTimePage(Integer user_id, Date log_time, String log_page) {
        return lookLogInfoMapper.getAllLookLogInfoByUserIdTimePage(user_id, log_time, log_page);
    }

    @Override
    public List<LookLogInfo> getAllLookLogInfoByRole(Integer role) {
        return lookLogInfoMapper.getAllLookLogInfoByRole(role);
    }

    @Override
    public PageInfo<LookLogInfo> getPageLookLogInfo(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<LookLogInfo> AllLookLogInfo=lookLogInfoMapper.getAllLookLogInfoAll();
        PageInfo<LookLogInfo> pageInfo=new PageInfo<>(AllLookLogInfo);
        return pageInfo;
    }
}
